#ifndef _FRUSTUM_H__
#define _FRUSTUM_H__

#include"Plane.h"
#include"Matrix.h"

class Frustum
{
public:
	enum Side { Near, Far, Top, Right, Bottom, Left, NumPlanes };
	Plane m_Planes[NumPlanes];		//Planes of the Frustum in camera space
	Vector3 m_NearClip[4];			//Verts of the near clip plane in camera space
	Vector3 m_FarClip[4];			//Verts of the far clip plane in camera space
public:
	float m_Fov;					//Field of view in radians
	float m_Aspect;					//Aspect ratio - width divided by height
	float m_Near;					//Near clipping distance
	float m_Far;					//Far clipping distance
	Matrix mWorld;

public:
	Frustum();
	Frustum(float aspect, float fov, float near, float far);

	void Initialize(const float fov, const float aspect, const float nearClip, const float farClip);

	bool Inside(const Vector3 &point) const;
	bool Inside(const Vector3 & point, const float radius) const;
	const Plane &Get(Side side) { return m_Planes[side]; }
	void SetFOV(float fov) { m_Fov=fov; this->Initialize(m_Fov, m_Aspect, m_Near, m_Far); }
	void SetAspect(float aspect) { m_Aspect = aspect; this->Initialize(m_Fov, m_Aspect, m_Near, m_Far); }
	void SetNear(float nearClip) { m_Near = nearClip; this->Initialize(m_Fov, m_Aspect, m_Near, m_Far); }
	void SetFar(float farClip) { m_Far = farClip; this->Initialize(m_Fov, m_Aspect, m_Near, m_Far); }
};

#endif